package com.jianyun.jyzs.model;

import android.util.Log;

import com.jianyun.jyzs.bean.MeUserInfo;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.model.imdoel.IMeFragModel;
import com.jianyun.jyzs.utils.LoginCache;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/5/28.
 */

public class MefrageModel implements IMeFragModel {

    private static MefrageModel model;

    private MefrageModel() {
    }

    public static MefrageModel getInstance() {
        if (model == null) {
            model = new MefrageModel();
        }
        return model;
    }


    @Override
    public void getUserInfo(String enterpriseCode, String userId, final OnGetUserInfoListener onGetUserInfoListener) {

        Api api = RetrofitHelper.builderErpHttp().create(Api.class);
        api.getUserinfo("getUserInfo", enterpriseCode, userId,"jyzs","Android","1.0.2")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<MeUserInfo>() {
                    @Override
                    protected void onResponse(MeUserInfo response) {
                        if (response.isResult()){
                            Log.i("test","我的："+response.toString());
                            onGetUserInfoListener.onSuccess(response);
                            LoginCache.getInstance().setUserDetaileInfo(response);
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                            onGetUserInfoListener.onException(msg);
                    }
                });
    }
}
